<template>
  <div>
    <common-head title="注册页"></common-head>
    <div class="wrap">
      <van-form @submit="onSubmit">
          <van-field
            v-model="user.username"
            name="username"
            label="用户名"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="user.pwd"
            type="password"
            name="pwd"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">点击注册</van-button>
          </div>
        </van-form>
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { regName } from '@api'
import { Toast } from 'vant'
export default {
  components: {
    CommonHead
  },
  data () {
    return {
      user: {
        username: '',
        pwd: ''
      }
    }
  },
  methods: {
    onSubmit (params) {
      regName(params).then(res => {
        console.log(this.user)
        console.log(res)
        if (res.data.code === 0) {
          Toast({
            type: 'success',
            message: '注册成功',
            onClose: () => {
              this.$router.replace('/login')
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap {
  .van-form{
    padding-top: 50px;
  }
}
</style>
